package com.mall.db.api;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.commons.utils.R;
import com.mall.db.mapper.UmsRoleResourceRelationMapper;
import com.mall.domain.UmsRoleResourceRelation;
import com.mall.interface1.api.UmsRoleResourceApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.awt.*;
import java.util.List;

@DubboService
public class UmsRoleResourceRelationApiIMpl implements UmsRoleResourceApi {
    @Autowired
    private UmsRoleResourceRelationMapper mapper;

    @Override
    public List<UmsRoleResourceRelation> findById(Integer roleId) {
        LambdaQueryWrapper<UmsRoleResourceRelation> q = new LambdaQueryWrapper<>();
        q.eq(UmsRoleResourceRelation::getRoleId, roleId);
        return mapper.selectList(q);
    }

    @Override
    public List<UmsRoleResourceRelation> listIds(Integer[] ids) {
        LambdaQueryWrapper<UmsRoleResourceRelation> q = new LambdaQueryWrapper<>();
        q.in(UmsRoleResourceRelation::getRoleId,ids);
        return mapper.selectList(q);
    }

    @Override
    public void save(Integer[] resourceIds, Integer roleId) {
        for (Integer resourceId : resourceIds) {
            UmsRoleResourceRelation a = new UmsRoleResourceRelation();
            a.setResourceId(Convert.toLong(resourceId));
            a.setRoleId(Convert.toLong(roleId));
            mapper.insert(a);
        }
    }
}
